package answer.service.Impl;

import answer.mapper.WrongMapper;
import answer.service.WrongService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import commons.pojo.Wrong;
import commons.vo.LivegoodsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WrongServiceImpl implements WrongService {
    @Autowired
    private WrongMapper wrongMapper;

    @Override
    public LivegoodsResult getWrong(int user) {
        QueryWrapper<Wrong> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("userid",user);
//        Page<Wrong> wrongPage = wrongMapper.selectPage(new Page<>(page, rows), objectQueryWrapper);
        List<Wrong> wrongs = wrongMapper.selectList(objectQueryWrapper);
        return LivegoodsResult.ok(wrongs);
    }

    @Override
    public LivegoodsResult AddWrong(Wrong wrong) {
        wrongMapper.insert(wrong);
        return LivegoodsResult.ok("插入成功");
    }

    @Override
    public LivegoodsResult WrongMove(int user, int id) {
        QueryWrapper<Wrong> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("userid",user);
        objectQueryWrapper.eq("id",id);
        int delete = wrongMapper.delete(objectQueryWrapper);
        return LivegoodsResult.ok("删除成功");
    }
}
